﻿using DirectSell.Common.CodeHelp;
using DirectSell.Common.Session;
using DirectSell.IBLL;
using DirectSell.Model.Manager;
using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DirectSell.WebLayer.Controllers
{
    /// <summary>
    /// 后台登录
    /// </summary>
    public class ManagerLoginController : Controller
    {
        #region 注入
        [Dependency("ManagerLogin")]
        protected IManagerOperation _service { get; set; }
        #endregion

        #region 首页
        /// <summary>
        /// 后台登录首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }
        #endregion

        #region 登录
        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns>
        public ManagerRespCode Login(LoginReq req)
        {
            var checkcode = SessionHelper.GetSession("ManagerCheckCode").ToString();
            if (checkcode == null || checkcode != req.checkCode)
            {
                return ManagerRespCode.验证码错误;
            }
            return _service.DoOperation(req);
        }
        #endregion

        #region 获取图片验证码--郭文昊--2018年10月28日23:36:26
        /// <summary>
        /// 获取图片验证码 
        /// </summary>
        /// <returns></returns>
        public ActionResult GetImageValiDateCode()
        {
            //获得验证码
            string code = ValidateCode.GetRandNumber(4);
            byte[] bytes = ValidateCode.CreateCheckCode(code);
            //验证码写入Session
            SessionHelper.SetSession("ManagerCheckCode", code);
            return File(bytes, @"image/jpeg");
        }
        #endregion

    }
}